package com.skyline.energy.definition;

import java.lang.reflect.Method;

import com.skyline.energy.annotation.BatchUpdate;
import com.skyline.energy.annotation.Query;
import com.skyline.energy.annotation.Update;
import com.skyline.energy.exception.DaoGenerateException;

public class JdbcDefinitionCollection {
	private JdbcQueryDefinition queryDefinition;
	private JdbcUpdateDefinition updateDefinition;
	private JdbcBatchUpdateDefinition batchUpdateDefinition;

	public JdbcDefinitionCollection(Method method) throws DaoGenerateException {
		Query query = method.getAnnotation(Query.class);
		if (query != null) {
			queryDefinition = new JdbcQueryDefinition(method);
		}

		Update update = method.getAnnotation(Update.class);
		if (update != null) {
			updateDefinition = new JdbcUpdateDefinition(method);
		}

		BatchUpdate batchUpdate = method.getAnnotation(BatchUpdate.class);
		if (batchUpdate != null) {
			batchUpdateDefinition = new JdbcBatchUpdateDefinition(method);
		}

	}

	public JdbcQueryDefinition getQueryDefinition() {
		return queryDefinition;
	}

	public JdbcUpdateDefinition getUpdateDefinition() {
		return updateDefinition;
	}

	public JdbcBatchUpdateDefinition getBatchUpdateDefinition() {
		return batchUpdateDefinition;
	}

	public boolean needJdbcOpration() {
		return (queryDefinition != null || updateDefinition != null || batchUpdateDefinition != null);
	}
}
